<?php
$this->lang->load('template');
$this->load->view('admin/common/header',array('_user'=>$_user,'modules'=>$modules,'pageTitle'=>'分类管理'));
$setting = array(
	'attr' => array(
		'class' => 'index'
	),
	'fields' => array(
		//'id' => array('label'=>__('feild.id')),
		'name' => array('label' => $this->lang->line('tpl_categoryname'),'filter'=>'__doFilter' ),
		'type'	=> array('label'=> $this->lang->line('tpl_categorytype')),
		'status' => array('label' => $this->lang->line('tpl_status'),'filter'=>'__doFilter','is_sort'=>true ),
		'sorts' => array('label' => $this->lang->line('tpl_sorts'),'is_sort'=>true ),
		'action'	=> array('label' => $this->lang->line('tpl_actions'),'filter'=>'__doFilter' ),
	),
	'data' => $result,
);

function __doFilter($f,$r){
	$str = isset($r[$f])?$r[$f]:'';
	if($f=='name'){
		$str = str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;',$r['level']).'-'.$str;
	}elseif($f=='status'){
		return sprintf('<img src="%s">',__st($r[$f]));
	}elseif($f=='action'){
		$str = '<a href="'.site_url('admin/categories/edit/'.$r['id']).'" class="edit_link" title="编辑"><img alt="Edit" src="'.base_url('images/admin/icons/edit.png').'" /></a>';
		if(!$r['have_sub']){
			$str .= '&nbsp;';
			$str .= '<a href="'.site_url('admin/categories/remove/'.$r['id']).'" class="remove_link" rel="'.$r['id'].'" title="删除"><img alt="Edit" src="'.base_url('images/admin/icons/delete.png').'" /></a>';
		}
	}
	$str = empty($str) ? '&nbsp;&nbsp;':$str;
	return $str;
}
?>
<style>
.tr span {
	clear:both;
	display:block;
	color:#999
}
</style>
<script language="javascript">
$(document).ready(function(){
	$('.remove_link').click(
		function(event){
			event.preventDefault();
			url = this.href+'?format=json';
			return Admin.remove(
				url,
				'您确定删除该数据吗？'
			);
		}
	);
	$('.sort_link').click(
		function(event){
			event.preventDefault();
			field = this.attributes['field'].value;;
			return urlRequest.setSort(field);
		}
	);
});

</script>
<div class="clear tile_bg" id="content">
  <div class='toolbar'>
    <ul class='actions'>
      <li> <a href="<?=site_url('admin/categories/create')?>" class="button" id="new_item_link"><span><img alt="Add" src="<?=base_url('images/admin/icons/add.png')?>" />添加</span></a> </li>
    </ul>
    <br class='clear' />
  </div>
  <h1>
  分类列表 </h1>
  <div id="new-item"></div>
  <?=htmlTable($setting);?>
</div>
</div>
<?php $this->load->view('admin/common/footer');?>